home *** CD-ROM | disk | FTP | other *** search
- XREF2.BAS - A cross-reference utility for GFA Basic, written by
- Don Edwards
-
- Given a GFA-BASIC program listing (use the SAVE,A function in
- the editor), for example XREF.LST, it will produce a line-numbered
- listing (XREF.LNM for this example, unless you specify something
- else) and a cross-reference file (XREF.XRF), both on disk.
-
- The .LNM file is just like the .LST file, except it has a
- line number adding 5 characters to the front of each line. The
- .XRF file is formatted as a report, with the variable / procedure
- / label name in the first 20 characters of one line and line
- numbers in positions 21-60 of as many lines as needed.
-
- Operation: I like fileselector boxes. So when you run the
- program, you will be given a fileselector box and asked to pick
- out a .LST file to process. (Checking CANCEL will terminate the
- program.) Once that is done, two more fileselectors let you change
- the .LNM and .XRF files if you like.
-
- Finally, a FOURTH file selector asks you to identify the
- DRIVE (and folder, if you like) for temporary files. In this box,
- the drive and folder are the only things that matter - a filename
- given will be ignored, and in fact you don't have to give a
- filename at all! (Just click the OK box.)
-
- I strongly encourage you to put the temporary files on a hard
- disk or RAMdisk, this program is slow enough anyway. (If you like
- it but think it's too slow, I accept donations to my computer fund
- :-> )
-
- Once that is done, it prints the names of 4 temporary files
- (not that you really care, it erases them when it's done) and goes
- to work. Expect messages from the following stages:
-
- Reading the source
- Sorting
- Combining
- Formatting the report
-
- And then it's done! (But don't hold your breath.)
-
-
-
- Hacker's notes:
-
- The "reading the source" stage has several things you may
- find interesting. There is, of course, a stripped-down parser to
- keep track of the current line as it identifies and gathers words,
- but throws away numbers, quoted strings, and other things. You may
- want to take a look at the character-input routine, which uses a
- 10K buffer, and the "skip-the-rest-of-the-line" routine (used for
- remarks and data statements) which has to cooperate with that
- buffer.
-
- Once a word is identified, it may be a BASIC keyword which we
- don't want to include in the cross-reference. A list of BASIC
- keywords is included into the program (in DATA statements, but
- it's read into an array) and a binary search is used to quickly
- look through the nearly 250 entries.
-
- The XREF program listing comes out with nearly 500
- references, and there are larger programs. So the references are
- written to a temporary file, and the sort phase is a 2-way merge.
- This is a useful sorting technique for large files; sort temporary
- files (including the final output file) typically take a bit over
- twice as much space as the input. In this case, the input can be
- discarded after the first sort pass. For the theoretically
- inclined, a merge sort is among those which achieve theoretical
- peak performance - in practical terms, a 3-, 4- or more-way merge
- would be faster (as it would also be if the program kept more than
- two records in memory at one time) but would also be harder to
- program.
-
- The only fancy thing about the combining stage is that the
- line numbers, treated as numbers in the sort, are treated as
- strings and concatenated together with intervening spaces.
-
- The report phase is worth a bit of attention for those who
- haven't written reports (I've written too many, mostly in Cobol -
- blech!). An interesting touch is how the concatenated line numbers
- are spread out to be right-justified in 5-column fields. An
- indicator points to the leftmost digit of the number; from there
- Ie search for a space (or the end of the string), find the length,
- and use the VAL function to extract the number for a PRINT USING.
- Then the indicator is advanced.
-
- Nothing really fancy, just a lot of nitpicking details that
- have to all be right.
-
-
-